//user数据模型

const Sequelize = require('sequelize')

let Model = Sequelize.Model

class User extends Model {}

//定义数据模型结构

User.init({
    id: {
        type: Sequelize.INTEGER.UNSIGNED,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
        comment: '表id'
    },
    userId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        defaultValue: '',
        comment: '用户id'
    },
    userEmail: {
        type: Sequelize.STRING(30),
        allowNull: false,
        comment: '用户邮箱'
    },
    userPassword: {
        type: Sequelize.STRING(40),
        allowNull: false,
        comment: '用户密码'
    },
    nickName: {
        type: Sequelize.STRING(20),
        allowNull: true,
        defaultValue: '',
        comment: '用户昵称'
    }
}, {
    //表配置
    modelName: 'User',
    timestamps: true,
    paranoid: true,
    underscored: true,
    freezeTableName: false, //不允许修改表名
    sequelize
})

//创建表,(表存在不创建)
User.sync({
    force: false
})

//导出模型对象
module.exports = User